<template>
  <div class="city top-layer">
    <div class="top">
      <van-search
        v-model="searchValue"
        placeholder="城市/区域/位置"
        shape="round"
        show-action
        @cancel="cancelClick"
      />
      <van-tabs v-model:active="tabActive" color="#ff9854" line-height="2">
        <template v-for="(value, key, index) in allCities" :key="key">
          <van-tab :title="value.title" :name="key"></van-tab>
        </template>
      </van-tabs>
    </div>

    <div class="content">
      <template v-for="(value, key, index) in allCities" :key="key">
        <CityGroup v-show="tabActive === key" :groupData="value"></CityGroup>
      </template>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from "vue";
import { storeToRefs } from "pinia";
import { useRouter } from "vue-router";
// import { getCityAll } from "@/services/index"
import useCityStore from "@/stores/modules/city";

import CityGroup from './components/city-group.vue'

const router = useRouter();

const searchValue = ref("");
const tabActive = ref(0);

// 返回
function cancelClick() {
  router.back();
}

// 请求：城市数据
// const allCities = ref({});
// getCityAll().then(res => {
//   allCities.value = res.data;
// })
const cityStore = useCityStore();
cityStore.fetchAllCitiesData();
const { allCities } = storeToRefs(cityStore);
// 使用计算属性，计算属性中数据发生变化则重新计算
const currentGroup = computed(() => allCities.value[tabActive.value]);



</script>

<style lang="less" scoped>
.city {
  .top {
    position: relative;
    z-index: 10;
  }

  // 局部滚动
  .content {
    height: calc(100vh - 98px);
    overflow-y: auto;
  }
}
</style>